import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'

Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        token: "",
        userInfo: {},
        isAuth: false
    },
    getters: {

    },
    //修改数据的方法
    mutations: {
		saveToken(state, token) {
		    state.token = token
		    if (token) {
		        console.log('token',token)
		        state.isAuth = true
		    }
		},
		saveUserInfo(state, userInfo) {
		    state.userInfo = userInfo
		},
		userLogout(state) {
		    state.token = ""
		    state.isAuth = false
		    state.userInfo = {}
		}   
    },
    //获取数据的方法
    actions: {
        
    },
	plugins: [
	   createPersistedState()
	]
})

export default store